package me.firstapp.common.module.base;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Locale;

import org.markdown4j.Markdown4jProcessor;
import org.ocpsoft.prettytime.PrettyTime;

import me.firstapp.common.utils.StrUtils;

public class JsonBase implements Serializable {
	private static final long serialVersionUID = -696279591490176327L;
	protected Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 解析markdown文章
	 * 
	 * @param content
	 */
	public String markedownToHtml(String content) {
		if (StrUtils.isNULL(content)) {
			return "";
		}
		String hContent = "";
		// markdown 转 html 并返回
		try {
			hContent = new Markdown4jProcessor().process(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return hContent;
	}

	/**
	 * 格式化日期
	 *
	 * @param date
	 */
	public String formatDate(Date date) {
		String dateStr = "";
		if (date != null) {
			PrettyTime prettyTime = new PrettyTime(Locale.CHINA);
			dateStr = prettyTime.format(date);
		}
		return dateStr.replace(" ", "");
	}

}
